/**
 * Created by fyf on 2016/9/2.
 */
let multer = require('multer');
let fieldList = {
    'HeadImgUrl': {storePath: config.project_dir + '/public/headImg', prefix: 'headImgUrl-', imageUrl: '/headImg/'}
};
let storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, fieldList[file.fieldname].storePath)
    },
    filename: function (req, file, cb) {
        let fileName = file.originalname.split('.');
        let newFileName = fieldList[file.fieldname].prefix + Date.now() + '.' + fileName[fileName.length - 1];
        file.imageUrl = fieldList[file.fieldname].imageUrl + newFileName;
        cb(null, newFileName)
    }
});

exports.upload = multer({storage: storage});